package db

import (
	"context"
	"log"
	"time"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

// 提取 MongoDB 初始化函数
func InitMongoDB() *mongo.Database {
	opts := options.Client().
		ApplyURI("mongodb://localhost:27017").
		SetConnectTimeout(10 * time.Second).
		SetMaxPoolSize(100)
	client, err := mongo.Connect(context.TODO(), opts)
	if err != nil {
		log.Fatal("无法连接到MongoDB: ", err)
	}
	log.Printf("数据库连接成功")
	return client.Database("trajectory")
}
